package homeworks.cjt2009.homework1.tsetso.solution;

import java.util.Collection;

public class Room implements Comparable<Room> {

	// --- Fields --------------------------------------------------------------
	private int number;
	private int capacity;
	private float rate;

	// --- Constructors -----------------------------------------------------
	public Room(int number, int capacity, float rate) {
		this.number = number;
		this.capacity = capacity;
		this.rate = rate;
	}

	public Room(Room room) {
		this.number = room.getNumber();
		this.capacity = room.getCapacity();
		this.rate = room.getRate();
	}

	// --- Getters & Setters ------------------------------------------------
	public int getNumber() {
		return number;
	}

	public int getCapacity() {
		return capacity;
	}

	public void setCapacity(int capacity) {
		this.capacity = capacity;
	}

	public float getRate() {
		return rate;
	}

	// --- Methods -------------------------------------------------------------
	@Override
	public String toString() {
		String resultString = "Room: number= " + number + ", capacity= "
				+ capacity + ", rate= " + rate;
		return resultString;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof Room)) {
			throw new IllegalArgumentException("Incorrect input object "
					+ "in equals method of Room class.");
		}
		return this.getNumber() == ((Room) obj).getNumber();
	}

	@Override
	public int hashCode() {
		return getNumber();
	}

	@Override
	public int compareTo(Room room) {
		return getNumber() - room.getNumber();
	}

	public static String toStringRooms(Collection<Room> rooms) {
		if (rooms == null) {
			throw new IllegalArgumentException("Null-argument passed to "
					+ "toStringRooms() method in class Room");
		}

		StringBuilder resultString = new StringBuilder();
		for (Room room : rooms) {
			resultString.append("\t").append(room).append("\n");
		}
		return resultString.toString();
	}

}
